
let initGL width height =
        GlDraw.viewport 0 0 width height;
 GlMat.mode `modelview;
         GlMat.load_identity ();
         GluMat.look_at ~eye:(0.5, 0.6, 1.) ~center:(0.,0.,0.) ~up:(1.,0.5,0.);

         GlDraw.shade_model `smooth;
         GlClear.color (0.,0.,0.) ;
   GlClear.depth 1.0;
   GluMat.perspective
     ~fovy:75.
     ~aspect:((float_of_int width)/.(float_of_int height))
     ~z:(1.,2000.0);
   Gl.enable `depth_test;
   GlFunc.depth_func `lequal

let drawGLScene () =
        
  GlClear.clear [`color; `depth];
  GlMat.load_identity ();  
 (* GlMat.rotate ~angle:(angle (Sys.time ())) ~z:1. (); *)
  
  GlDraw.begins `triangles;
  (*1e tri*)
  GlDraw.color (1.0, 0.0, 0.0);
  GlDraw.vertex3 (0.0, 1.0, 0.0);
  GlDraw.color (0.0, 1.0, 0.0);
  GlDraw.vertex3 (-1.0, -1.0, 1.0);
  GlDraw.color (0.0, 0.0, 1.0);
  GlDraw.vertex3 (1.0, -1.0, 1.0);

  GlDraw.color (1.0, 0.0, 0.0);
  GlDraw.vertex3 (0.0, 1.0, 0.0);
  GlDraw.color (0.0, 0.0, 1.0);
  GlDraw.vertex3 (1.0, -1.0, 1.0);
  GlDraw.color (0.0, 1.0, 0.0);
  GlDraw.vertex3 (1.0, -1.0, -1.0);

  GlDraw.color (1.0, 0.0, 0.0);
  GlDraw.vertex3 (0.0, 1.0, 0.0);
  GlDraw.color (0.0, 1.0, 0.0);
  GlDraw.vertex3 (1.0, -1.0, -1.0);
  GlDraw.color (0.0, 0.0, 1.0);
  GlDraw.vertex3 (-1.0, -1.0, -1.0);

  GlDraw.color (1.0, 0.0, 0.0);
  GlDraw.vertex3 (0.0, 0.4, 0.0);
  GlDraw.color (0.0, 0.0, 1.0);
  GlDraw.vertex3 (-1.0, -1.0, -1.0);
  GlDraw.color (0.0, 1.0, 0.0);
  GlDraw.vertex3 (-1.0, -1.0, 1.0);
 (*2e tri*)
 GlDraw.color (255.0, 255.0, 255.0);
  GlDraw.vertex3 (1.0, 1.0, 4.0);
  GlDraw.color (5.0, 1.0, 0.0);
  GlDraw.vertex3 (-6.0, -2.0, 5.0);
  GlDraw.color (0.0, 0.0, 1.0);
  GlDraw.vertex3 (4.0, -6.0, 8.0);

  GlDraw.color (5.0, 0.0, 0.0);
  GlDraw.vertex3 (8.0, 1.0, 9.0);
  GlDraw.color (0.0, 0.0, 1.0);
  GlDraw.vertex3 (13.0, -15.0, 10.0);
  GlDraw.color (0.0, 1.0, 0.0);
  GlDraw.vertex3 (12.0, -10.0, -5.0);

  GlDraw.color (1.0, 0.0, 0.0);
  GlDraw.vertex3 (4.0, 1.0, 3.0);
  GlDraw.color (0.0, 1.0, 0.0);
  GlDraw.vertex3 (5.0, -4.0, -3.0);
  GlDraw.color (5.0, 6.0, 1.0);
  GlDraw.vertex3 (-1.0, -1.0, -1.0);

  GlDraw.color (1.0, 0.0, 0.0);
  GlDraw.vertex3 (1.0, 0.4, 0.6);
  GlDraw.color (0.0, 0.0, 1.0);
  GlDraw.vertex3 (-5.0, -6.0, -8.0);
  GlDraw.color (0.0, 1.0, 0.0);
  GlDraw.vertex3 (-4.0, -7.0, 9.0);

  GlDraw.ends ();
  Glut.swapBuffers() 

let createWin width height  = 
(* let w = GWindow.window 
    ~title:"sdfgsdfg"
    ~width:width
    ~height:height 
    ~resizable:false ()  in
 ignore(w#connect#destroy ~callback:GMain.quit ) ; 

 let area = GlGtk.area [`DOUBLEBUFFER;`RGBA;`DEPTH_SIZE 16;`BUFFER_SIZE 16]
      ~width:width ~height:height ~packing:w#add () in 
      area#connect#display ~callback:(drawGLScene area);
  w#show () *)
  let argv = Glut.init Sys.argv in 
  Glut.initDisplayMode ~depth:true  ~double_buffer:true;
  Glut.initWindowSize width height;
  Glut.createWindow ~title:"fasdf";
  Glut.displayFunc ~cb:drawGLScene;
  Glut.mainLoop ()


let main () = 
    createWin 800 600 ;
    initGL 800 600
let _ = main () 
